package com.wlsmartlock.Utils;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

public class ActivityCollector {
    public static List<Activity> activities = new ArrayList<>();

    public static void addActivity(Activity activity){
        activities.add(activity);
    }

    public static void removeActivity(Activity activity){
        activities.remove(activity);
    }

    public static void finishAll(){
        for(Activity activity : activities){
            if(!activity.isFinishing()){
                String xxx = activity.getClass().getSimpleName();
                if(activity.getClass().getSimpleName().equalsIgnoreCase("MainActivity") ){
                    if(App.mBleReceiver != null){
                        activity.unregisterReceiver(App.mBleReceiver);
                        App.mBleReceiver = null;
                    }
                }
                activity.finish();
            }
        }

        App.mConnectionState = 0;
    }
}
